<?php
include('connection/connection.php');
 $distId=$_REQUEST['distId'];
 //$file1=$_REQUEST['fl'];
 $file = "water_quality.csv";
  header("Content-Disposition: attachment; filename=$file");
	//header("Content-Type:application/vnd.ms-excel");
  header("Content-Type:application/octet-stream");
  //$querystring="select * from ".$file1." where district_id=".$distId."";
  $querystring="SELECT date,l.block_name,l.panchayat_name,l.village_name,l.habitation_name,detail.type_habit,source_type,location,functional_status,para_ph,para_tds,para_cl,para_f,para_no3,bact from tbl_dtls_q3_loc loc,tbl_dtls_q3_water_source_detail detail,tbl_lookup_location l where loc.district_id=".$distId." and loc.id=detail.loc_id and l.district_id=loc.district_id and l.block_id=loc.block_id and l.panchayat_id=loc.panchayat_id and l.village_id=loc.village_id and l.habitation_name=detail.habitation_name";
  $result_csv=mysql_query($querystring);
  $flag = false;
while(false !== ($r1=mysql_fetch_assoc($result_csv)))
{
if(!$flag) {
echo implode(",", array_keys($r1)) . "\n";
$flag = true;
}
echo implode(",", array_values($r1))."\n" ;
}

?>
